<html>
<head><meta charset="utf-8"><title>patching libc for a new target · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html">patching libc for a new target</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="204328949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204328949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brian Cain <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204328949">(Jul 19 2020 at 02:42)</a>:</h4>
<p>I'm trying to build libstd for hexagon-unknown-linux-musl.  There's some pieces of what I need for this upstream so far.</p>
<p>I am not sure what's the best way to start, so for now I'm just building libstd via bootstrap.  First I ran into build issues for libunwind -- the build flags specified in <code>build.rs</code> cause errors w/clang (there's no modern gnu toolchain for my target os, only llvm+clang).   I can workaround that for now by omitting the "-std=c99" and "-std=c++11" flags.  Now I see errors when libstd tries to build the dependent <code>panic_unwind</code> crate.   panic_unwind specifies a version of the libc crate old enough that it didn't have hexagon-unknown-linux-musl support.  I tried patching the libc crate by: (1) specifying a newer version of libc in src/panic_unwind/Cargo.toml or (2) adding a <code>[patch.crates-io]</code> to specify a newer libc to any/all of src/tools/rustc-std-workspace-*/Cargo.toml or src/libstd/Cargo.toml.  Those all seem ineffective - as if they are not in scope for this crate's build.  Has anyone got a good suggestion as how to make progress?</p>
<p>I've also tried <code>cargo xbuild</code> of libstd but ran into issues using the unpatched source for libunwind.  I can probably workaround this issue by hacking up the rust-src component.</p>



<a name="204347232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204347232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204347232">(Jul 19 2020 at 12:28)</a>:</h4>
<p>I happen to be doing the exact same thing for <code>aarch64-apple-darwin</code>. You need to <a href="https://github.com/shepmaster/rust/commit/2bd261bfb21768e5192a5115ec33585782de2fae#diff-80398c5faae3c069e4e6aa2ed11b28c0R71">add the <code>patch</code> section in the workspace's Cargo.toml</a> then run <code>cargo update -p libc</code>.</p>



<a name="204347599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204347599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204347599">(Jul 19 2020 at 12:38)</a>:</h4>
<p>Maybe it would be good to document this somewhere? Rustc-dev-guide seems like a good place</p>



<a name="204347816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204347816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204347816">(Jul 19 2020 at 12:44)</a>:</h4>
<p>Maybe a "so you want to target a new platform" section.</p>



<a name="204354442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204354442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brian Cain <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204354442">(Jul 19 2020 at 14:58)</a>:</h4>
<p>Yeah, thanks!  That seems to help get me further.</p>



<a name="204361887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204361887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204361887">(Jul 19 2020 at 17:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/patching.20libc.20for.20a.20new.20target/near/204347599">said</a>:</p>
<blockquote>
<p>Maybe it would be good to document this somewhere? Rustc-dev-guide seems like a good place</p>
</blockquote>
<p><a href="https://github.com/rust-lang/rustc-dev-guide/pull/805">https://github.com/rust-lang/rustc-dev-guide/pull/805</a></p>



<a name="204362223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204362223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brian Cain <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204362223">(Jul 19 2020 at 17:46)</a>:</h4>
<p>I appreciate this doc update -- this is really useful.</p>
<p>Along these lines -- are there any companies/teams who vendor their own rust toolchain?  I'd be pretty curious about that process too.</p>



<a name="204362318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204362318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204362318">(Jul 19 2020 at 17:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="322951">Brian Cain</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/patching.20libc.20for.20a.20new.20target/near/204362223">said</a>:</p>
<blockquote>
<p>are there any companies/teams who vendor their own rust toolchain</p>
</blockquote>
<p>Like <a href="#narrow/stream/122651-general/topic/building.20rustc.20and.20missing.20CXXFLAGS/near/203996115">this person</a>?</p>



<a name="204363075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204363075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brian Cain <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204363075">(Jul 19 2020 at 18:01)</a>:</h4>
<p>hmm.  maybe, sounds like it.  So that's on behalf of google?</p>



<a name="204363338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204363338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Brian Cain <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204363338">(Jul 19 2020 at 18:05)</a>:</h4>
<p>Interesting -- I never considered updating the <code>cc</code> crate.  But I see now that it's a dependency of <code>src/libunwind/</code>.  Maybe that would be a way to address the compilation failures that I worked around by editing  the <code>build.rs</code>?</p>



<a name="204364140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204364140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204364140">(Jul 19 2020 at 18:18)</a>:</h4>
<p>In my case, I needed to update it to add <code>-arch whatever</code> to the C compiler options. IIRC, backtrace and compiler-builtins were the two primary crates that had C code in them.</p>



<a name="204365065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204365065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204365065">(Jul 19 2020 at 18:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/patching.20libc.20for.20a.20new.20target/near/204361887">said</a>:</p>
<blockquote>
<p><a href="https://github.com/rust-lang/rustc-dev-guide/pull/805">https://github.com/rust-lang/rustc-dev-guide/pull/805</a></p>
</blockquote>
<p>left a review, thanks for the PR :)</p>



<a name="204365341"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/patching%20libc%20for%20a%20new%20target/near/204365341" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/patching.20libc.20for.20a.20new.20target.html#204365341">(Jul 19 2020 at 18:51)</a>:</h4>
<div class="message_inline_image"><a href="https://i.imgflip.com/48rnxw.jpg"><img src="https://i.imgflip.com/48rnxw.jpg"></a></div>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>